//
//  HomeModel.swift
//  SwiftUI_App
//
//  Created by qingzhou on 2021/6/25.
//

import Foundation

struct HomeModel:Hashable, Codable, Identifiable {
    var id: Int
    var bannerImages:Array<String>
}

///解析本地数据
func load<T: Decodable>(_ filename: String) -> T {
    let data: Data
    
    guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else {
        fatalError("Couldn't find \(filename) in main bundle.")
    }
    
    do {
        data = try Data(contentsOf: file)
    } catch {
        fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
    }
    
    
    do {
        let decoder = JSONDecoder()
        return try decoder.decode(T.self, from: data)
    } catch {
        fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
    }
}
